package pervasivePositioning.pos;
import android.location.Location;

public class MaxSpeedStrategy extends ReportingStrategy {
	
	Location lastFix = null;
	float maxSpeed = 0;

	public MaxSpeedStrategy() {
		lastFix = null;
	}

	public MaxSpeedStrategy(float ms) {
		setValue(ms);
		lastFix = null;
	}	
	
	public void setValue(float ms) {
		maxSpeed = ms;
	}

	@Override
	public boolean reportPosition(Location newloc) {
		if(lastFix == null)
			return true;
		
		float dist = newloc.distanceTo(lastFix);
		long deltaTime = newloc.getTime() - lastFix.getTime();
		
		float speed = (deltaTime > 0)? dist/((float) deltaTime) : 0;
		if (speed < maxSpeed) {
			return false;			
		}  
		lastFix = newloc;
		return true;
	}
	
	@Override
	public String getName() {
		return "MaxSpeedStrategy";
	}

	@Override
	public String getValueName() {
		return "maxSpeed";
	}

	@Override
	public String getConfig() {
		return String.valueOf(maxSpeed);
	}

	@Override
	public float getValue() {
		return maxSpeed;		
	}
}
